<template>
	<view class="layout">
		<view class="navbar" :style="{ backgroundColor: backgroundColor }">
			<view class="statusBar" :style="{height:getStatusBarHeight+'px'}"></view>
			<view class="titleBar" :style="{height:getTitleBarHeight+'px'}">
				<block>
					<view v-if="back" class="goBack" @click="goBack" :style="{top:getStatusBarHeight+'px'}">
						<uni-icons type="back" color="#fff" size="18"></uni-icons>
					</view>
					<view class="title" v-if="title">{{title}}</view>
					<navigator  v-if="search" url="/pages/search/search" class="search">
						<uni-icons class="icon" type="search" color="#888" size="18"></uni-icons>
						<text class="text">搜索</text>
					</navigator>
				</block>
			</view>
		</view>
		<view class="fill" :style="{height:getStatusBarHeight+getTitleBarHeight+'px'}"></view>
	</view>
</template>

<script>
	import {
		getStatusBarHeight,
		getTitleBarHeight,
		getNavBarHeight,
	} from "../../utils/system.js"
	export default {
		name: "custom-nav-bar",
		props: {
			title: {
				type: String,
				default: ""
			},
			back: {
				type: Boolean,
				default: false,
			},
			search:{
				type: Boolean,
				default: true,
			},
			backgroundColor:{
				type: String,
				default: "linear-gradient(to bottom, transparent, rgba(244, 249, 253, 1) 600rpx),linear-gradient(to right, #51A9FB 20%, #A4D8FC)"
			}
		},
		computed: {
			getStatusBarHeight() {
				return uni.getSystemInfoSync().statusBarHeight || 15
			},
			getTitleBarHeight() {
				if (uni.getMenuButtonBoundingClientRect()) {
					let {
						top,
						height
					} = uni.getMenuButtonBoundingClientRect();
					return height + (top - getStatusBarHeight()) * 2
				} else {
					return 40;
				}
			},
		},
		data() {
			return {
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
		},
		created() {
		},
		onReady() {},
	}
</script>

<style lang="scss" scoped>
	.layout {
		.navbar {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			z-index: 10;
			.statusBar {}
			.titleBar {
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				.goBack {
					width: 27px;
					height: 27px;
					background: rgba(223,237,225, 0.5);
					left: 30rpx;
					margin-left: 0;
					border-radius: 100px;
					top: 0;
					backdrop-filter: blur(10rpx);
					border: 2rpx solid rgba(255, 255, 255, 1);
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.title {
					font-size: 22px;
					font-weight: 700;
					// color: $text-font-color-1;
					color:#fff
				}

				.search {
					width: 360rpx;
					height: 50rpx;
					border-radius: 60rpx;
					background: rgba(255, 255, 255, 0.4);
					border: 1px solid #fff;
					margin-left: 20rpx;
					color: #999;
					font-size: 28rpx;
					display: flex;
					align-items: center;

					.icon {
						margin-left: 10rpx;
					}

					.text {
						padding-left: 10rpx;
					}
				}
			}
		}

		.fill {}
	}
</style>